package com.example.shuiyin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shuiyin.entity.MultipartUpload;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MultipartUploadMapper extends BaseMapper<MultipartUpload> {
    
    @Select("SELECT * FROM multipart_upload WHERE upload_id = #{uploadId}")
    MultipartUpload selectByUploadId(@Param("uploadId") String uploadId);
    
    @Select("SELECT * FROM multipart_upload WHERE upload_id = #{uploadId} AND user_id = #{userId}")
    MultipartUpload selectByUploadIdAndUserId(@Param("uploadId") String uploadId, @Param("userId") Long userId);
    
    @Update("UPDATE multipart_upload SET completed_parts = completed_parts + 1 WHERE upload_id = #{uploadId}")
    int incrementCompletedParts(@Param("uploadId") String uploadId);
    
    @Select("SELECT * FROM multipart_upload WHERE status = 'IN_PROGRESS' AND created_at < DATE_SUB(NOW(), INTERVAL 1 DAY)")
    List<MultipartUpload> selectExpiredUploads();
} 